package cn.com.hbhgkj.config;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Properties;

public class Constants {
	public static final String CONFIG_FILE_NAME = "config.properties";

	public static final String USER_SSID = "_CRS_USER_LOGIN_SSID";

	public static final String AGENT_USER_NAME = LoadConfig.getInstance()
			.getProperty("agent_username");
	public static final String AGENT_PASSWORD = LoadConfig.getInstance()
			.getProperty("agent_password");

	public static final String AGENT_DESC = LoadConfig.getInstance()
			.getProperty("agent_desc");
	public static final String AGENT_NAME = LoadConfig.getInstance()
			.getProperty("agent_name");

	public static final String AGENT_ADDRESS = LoadConfig.getInstance()
			.getProperty("agent_address");
	public static final String AGENT_POSTCODE = LoadConfig.getInstance()
			.getProperty("agent_postcode");

	public static final String AGENT_CONTACT = LoadConfig.getInstance()
			.getProperty("agent_contact");
	public static final String AGENT_PHONE = LoadConfig.getInstance()
			.getProperty("agent_phone");

	public static final String AGENT_EMAIL = LoadConfig.getInstance()
			.getProperty("agent_email");
	public static final String AGENT_MOBILE = LoadConfig.getInstance()
			.getProperty("agent_mobile");
	public static final String AGENT_FAX = LoadConfig.getInstance()
			.getProperty("agent_fax");

	public static final String INIT_PASSWORD = LoadConfig.getInstance()
			.getProperty("init_password");

}

/**
 * 用于加载配置文件
 * 
 * @author：Cody Dong
 * @date 2011-8-4-下午08:44:15
 * @since 2.0.0
 */
class LoadConfig {

	private Properties properties = new Properties();
	// 单例实现
	private static LoadConfig lc = new LoadConfig();

	/**
	 * 单例
	 * 
	 * @author Cody Dong
	 * @return LoadConfig
	 * @date 2011-8-4 下午08:44:06
	 * @since 2.0.0
	 */
	public static LoadConfig getInstance() {
		return lc;
	}

	private LoadConfig() {
		try {
			properties.load(getClass().getClassLoader().getResourceAsStream(
					Constants.CONFIG_FILE_NAME));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取key对应的value值
	 * 
	 * @author Cody Dong
	 * @param key
	 * @return String
	 * @date 2011-8-4 下午08:43:57
	 * @since 2.0.0
	 */
	public String getProperty(String key) {
		return properties.getProperty(key);
	}

	public HashMap getHashMap(String key) {
		HashMap hashMap = new HashMap();
		String data = getProperty(key);
		if (data != null) {
			String[] list = data.split(";");
			for (int i = 0; list != null && i < list.length; i++) {
				data = list[i];
				int len = data.indexOf(",");
				if (len > -1) {
					hashMap.put(data.substring(0, len), data.substring(len + 1));
				}
			}
		}
		return hashMap;
	}
}
